package com.example.xuwsh.myBatisPlus.core.update;

import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.core.toolkit.support.SFunction;
import com.example.xuwsh.myBatisPlus.core.interfaces.JuXiLambdaInterfaceWrapper;

import java.util.Collection;

/**
 * @Author: xuwsh
 * @Date: 2023/09/20/15:17
 * @Description:
 */
public class JuXiLambdaUpdateWrapper<T> extends LambdaUpdateWrapper<T> implements JuXiLambdaInterfaceWrapper<JuXiLambdaUpdateWrapper<T>, T> {
    public JuXiLambdaUpdateWrapper<T> setIfPresent(SFunction<T, ?> column, Object val) {
        if (ObjectUtil.isNotEmpty(val)) {
            return (JuXiLambdaUpdateWrapper<T>) super.set(column, val);
        }
        return this;
    }

    /**
     * 使用eq的时候，值不为空
     *
     * @param column
     * @param val
     * @return
     */
    @Override
    public JuXiLambdaUpdateWrapper<T> eqIfPresent(SFunction<T, ?> column, Object val) {
        if (ObjectUtil.isNotEmpty(val)) {
            return (JuXiLambdaUpdateWrapper<T>) super.eq(column, val);
        }
        return this;
    }

    @Override
    public JuXiLambdaUpdateWrapper<T> neIfPresent(SFunction<T, ?> column, Object val) {
        if (ObjectUtil.isNotEmpty(val)) {
            return (JuXiLambdaUpdateWrapper<T>) super.ne(column, val);
        }
        return this;
    }

    @Override
    public JuXiLambdaUpdateWrapper<T> gtIfPresent(SFunction<T, ?> column, Object val) {
        if (ObjectUtil.isNotEmpty(val)) {
            return (JuXiLambdaUpdateWrapper<T>) super.gt(column, val);
        }
        return this;
    }

    @Override
    public JuXiLambdaUpdateWrapper<T> geIfPresent(SFunction<T, ?> column, Object val) {
        if (ObjectUtil.isNotEmpty(val)) {
            return (JuXiLambdaUpdateWrapper<T>) super.ge(column, val);
        }
        return this;
    }

    @Override
    public JuXiLambdaUpdateWrapper<T> ltIfPresent(SFunction<T, ?> column, Object val) {
        if (ObjectUtil.isNotEmpty(val)) {
            return (JuXiLambdaUpdateWrapper<T>) super.lt(column, val);
        }
        return this;
    }

    @Override
    public JuXiLambdaUpdateWrapper<T> leIfPresent(SFunction<T, ?> column, Object val) {
        if (ObjectUtil.isNotEmpty(val)) {
            return (JuXiLambdaUpdateWrapper<T>) super.le(column, val);
        }
        return this;
    }

    @Override
    public JuXiLambdaUpdateWrapper<T> betweenIfPresent(SFunction<T, ?> column, Object val, Object val1) {
        if (ObjectUtil.isNotEmpty(val) && ObjectUtil.isNotEmpty(val1)) {
            return (JuXiLambdaUpdateWrapper<T>) super.between(column, val, val1);
        }
        if (ObjectUtil.isNotEmpty(val)) {
            return (JuXiLambdaUpdateWrapper<T>) ge(column, val);
        }
        if (ObjectUtil.isNotEmpty(val1)) {
            return (JuXiLambdaUpdateWrapper<T>) le(column, val1);
        }
        return this;
    }

    @Override
    public JuXiLambdaUpdateWrapper<T> notBetweenIfPresent(SFunction<T, ?> column, Object val, Object val1) {
        if (ObjectUtil.isNotEmpty(val) && ObjectUtil.isNotEmpty(val1)) {
            return (JuXiLambdaUpdateWrapper<T>) super.notBetween(column, val, val1);
        }
        if (ObjectUtil.isNotEmpty(val)) {
            return (JuXiLambdaUpdateWrapper<T>) lt(column, val);
        }
        if (ObjectUtil.isNotEmpty(val1)) {
            return (JuXiLambdaUpdateWrapper<T>) gt(column, val1);
        }
        return this;
    }

    @Override
    public JuXiLambdaUpdateWrapper<T> likeIfPresent(SFunction<T, ?> column, Object val) {
        if (ObjectUtil.isNotEmpty(val)) {
            return (JuXiLambdaUpdateWrapper<T>) super.like(column, val);
        }
        return this;
    }

    @Override
    public JuXiLambdaUpdateWrapper<T> noLikeIfPresent(SFunction<T, ?> column, Object val) {
        if (ObjectUtil.isNotEmpty(val)) {
            return (JuXiLambdaUpdateWrapper<T>) super.notLike(column, val);
        }
        return this;
    }

    @Override
    public JuXiLambdaUpdateWrapper<T> likeLeftIfPresent(SFunction<T, ?> column, Object val) {
        if (ObjectUtil.isNotEmpty(val)) {
            return (JuXiLambdaUpdateWrapper<T>) super.likeLeft(column, val);
        }
        return this;
    }

    @Override
    public JuXiLambdaUpdateWrapper<T> notLikeLeftIfPresent(SFunction<T, ?> column, Object val) {
        if (ObjectUtil.isNotEmpty(val)) {
            return (JuXiLambdaUpdateWrapper<T>) super.notLikeLeft(column, val);
        }
        return this;
    }

    @Override
    public JuXiLambdaUpdateWrapper<T> likeRightIfPresent(SFunction<T, ?> column, Object val) {
        if (ObjectUtil.isNotEmpty(val)) {
            return (JuXiLambdaUpdateWrapper<T>) super.likeRight(column, val);
        }
        return this;
    }

    @Override
    public JuXiLambdaUpdateWrapper<T> notLikeRightIfPresent(SFunction<T, ?> column, Object val) {
        if (ObjectUtil.isNotEmpty(val)) {
            return (JuXiLambdaUpdateWrapper<T>) super.notLikeRight(column, val);
        }
        return this;
    }

    @Override
    public JuXiLambdaUpdateWrapper<T> isNullIfPresent(SFunction<T, ?> column, Object val) {
        if (ObjectUtil.isEmpty(val)) {
            return (JuXiLambdaUpdateWrapper<T>) super.isNull(column);
        }
        return this;
    }

    @Override
    public JuXiLambdaUpdateWrapper<T> isNotNullIfPresent(SFunction<T, ?> column, Object val) {
        if (ObjectUtil.isNotEmpty(val)) {
            return (JuXiLambdaUpdateWrapper<T>) super.isNotNull(column);
        }
        return this;
    }

    @Override
    public JuXiLambdaUpdateWrapper<T> inListIfPresent(SFunction<T, ?> column, Collection<?> coll) {
        if (CollectionUtil.isNotEmpty(coll)) {
            return (JuXiLambdaUpdateWrapper<T>) super.in(column, coll);
        }
        return this;
    }

    @Override
    public JuXiLambdaUpdateWrapper<T> notInListIfPresent(SFunction<T, ?> column, Collection<?> coll) {
        if (CollectionUtil.isNotEmpty(coll)) {
            return (JuXiLambdaUpdateWrapper<T>) super.notIn(column, coll);
        }
        return this;
    }

    @Override
    public JuXiLambdaUpdateWrapper<T> inArrayIfPresent(SFunction<T, ?> column, Object... values) {
        if (ObjectUtil.isAllNotEmpty(values)) {
            return (JuXiLambdaUpdateWrapper<T>) super.in(column, values);
        }
        return this;
    }


    @Override
    public JuXiLambdaUpdateWrapper<T> notInArrayIfPresent(SFunction<T, ?> column, Object... values) {
        if (ObjectUtil.isAllNotEmpty(values)) {
            return (JuXiLambdaUpdateWrapper<T>) super.notIn(column, values);
        }
        return this;
    }

}
